package zozopo.manual;

import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

import zozopo.manual.operations.ReplyOS;

import zozopo.user.operations.UserTB;

public class DeleteRelyAction extends ActionSupport implements Action ,SessionAware,ServletRequestAware,ServletResponseAware{
	private Map<Object, Object> session;
	private int subjectId;
	private int replyId;
	
	
	private HttpServletRequest request;
	private HttpServletResponse response;
	
	public String execute(){
		
		
		ReplyOS replyOS = new ReplyOS();
	
		UserTB user = (UserTB) session.get("userInfo");
		
		if(user == null){
			return NONE;
		}

		try {
			if(('0' == user.getUser_limitflag().charAt(3))){
				return NONE;
			}else{
				if(!replyOS.deleteSubject(replyId)){
					response.getWriter().write(ERROR);
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
		
		
		replyOS.releaseConnection();
		
		try {
			response.sendRedirect("view.action?id="+subjectId);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return ERROR;
		}
		return ERROR;
	}
	public void setSession(Map arg0) {
		// TODO Auto-generated method stub
		session = arg0;
	}
	
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		request = arg0;
	}

	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		response = arg0;
	}
	
	public int getSubjectId() {
		return subjectId;
	}
	public void setSubjectId(int subjectId) {
		this.subjectId = subjectId;
	}
	public int getReplyId() {
		return replyId;
	}
	public void setReplyId(int replyId) {
		this.replyId = replyId;
	}
}
